@echo off
setlocal EnableDelayedExpansion
::Set var1=Hello ABC how are you
::Set var2=ABC
::Set result=!var1:%var2%=Beautiful!
::Echo [!result!]
::goto :eof


set year=%date:~6,4%
set month=%date:~3,2%
set day=%date:~0,2%
set hr=%time:~0,2%
set mn=%time:~3,2%
set sc=%time:~6,2%

set pattern=:000:031:059:090:121:151:181:212:243:273:304:334
::	000	31	jan	1
::	031	28	feb	5
::	059	31	mar 9
::	090	30	apr
::	120	31	may
::	151 30	jun
::	181	31	jul
::	212	31	aug
::	243	30	sep
::	273	31	oct
::	304	30	nov
::	334	31	dec
set /a offset=month*4 - 3
set month=!pattern:~%offset%,3!
:: test for leapyear, to set right number of days.
:: leap must be calculated outside of if, as otherwise the brackets break it.
set /a leap=(4-year%4)/4 > NUL
if %month% GTR 31 (
	set /a month=month+leap	> NUL
)
set /a year=year-1970 > NUL
echo %%year%%=%year%
set /a leaps=year/4 > NUL
echo %%leaps%%=%leaps%